package com.diaohw.module.file.obj.entity;

import cn.hutool.core.date.DateUtil;
import com.diaohw.platform.framework.db.flex.obj.model.BaseModel;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Table;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 文件信息 实体类。
 *
 * @author D-Hw
 * @since 2024-11-22 17:21:01
 */
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(description = "文件信息")
@Table("FILE")
public class FileDO extends BaseModel implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 文件类型
     */
    @Column("CONTENT_TYPE")
    @Schema(description = "文件类型")
    private String contentType;

    /**
     * 文件名称
     */
    @Column("FILENAME")
    @Schema(description = "文件名称")
    private String filename;

    /**
     * 文件大小
     */
    @Column("FILE_LENGTH")
    @Schema(description = "文件大小")
    private Long length;

    /**
     * 存储根目录名称
     */
    @Column("BUCKET")
    @Schema(description = "存储根目录名称")
    private String bucket;

    /**
     * 存储位置
     */
    @Column("PATH")
    @Schema(description = "存储位置")
    private String path;

    /**
     * 文件MD5
     */
    @Column("MD5")
    @Schema(description = "文件MD5")
    private String md5;

    /**
     * 文件后缀
     */
    @Column("EXT")
    @Schema(description = "文件后缀")
    private String ext;

    /**
     * 源ID
     */
    @Column("SOURCE_ID")
    @Schema(description = "源ID")
    private String sourceId;

    /**
     * OCR识别状态
     */
    @Column("OCR")
    @Schema(description = "OCR识别状态")
    private String ocr;

    /**
     * 文件状态
     */
    @Column("STATUS")
    @Schema(description = "文件状态")
    private String status;

    public String path() {
        LocalDateTime date = LocalDateTime.now();
        this.path = DateUtil.format(date, "yyyy/MM/dd") + "/" + md5.toUpperCase() + "." + ext;
        return this.path;
    }

}
